package com.jiyun.trainlist.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiyun.trainlist.service.TrainService;
import com.jiyun.vo.TrainVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("train")
public class TrainController {

    @Autowired
    TrainService trainService;

    @Autowired
    RedisTemplate redisTemplate;

    @RequestMapping("findPage")
    public Page<TrainVo>findPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize, @RequestBody TrainVo trainVo){
        return trainService.findPage(pageNum,pageSize,trainVo);
    }

//    参加培训
    @RequestMapping("goTrain")
    public String goTrain(@RequestParam Integer id){
        redisTemplate.opsForValue().set("go",id+"");
        return "欢迎来到参加培训页面";
    }


//    立即参加
    @RequestMapping("findPeopleandTime")
    public List<TrainVo>findPeopleandTime(){
        String a =(String) redisTemplate.opsForValue().get("go");
        return trainService.findPeopleandTime(Integer.parseInt(a));
    }

//    参加比赛
    @RequestMapping("goCanjia")
    public void goCanjia(){
        String a =(String) redisTemplate.opsForValue().get("go");
        trainService.goCanjia(Integer.parseInt(a));;
    }
}
